package ska

import (
	"gddgame.cc/galaxy/utils"
	"gddgame.cc/galaxy/utils/def"
	"github.com/sirupsen/logrus"
)

type topicHook struct {
	field string
	def.Recorder
}

func (hook *topicHook) Levels() []logrus.Level {
	// 启用正常的5个level
	return []logrus.Level{
		logrus.PanicLevel,
		logrus.FatalLevel,
		logrus.ErrorLevel,
		logrus.WarnLevel,
		logrus.InfoLevel,
	}
}

func (hook *topicHook) Fire(entry *logrus.Entry) error {
	if topic, ok := entry.Data[hook.field]; ok {
		hook.Recorder.Send(utils.ToString(topic), entry.Data, entry.Message)
	}
	return nil
}
